<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .img {
        width: 355px;
        height: 355px;
        background-image: url("./images/banner.png");
      }

      @media screen and (-webkit-min-device-pixel-ratio: 2) {
        .img {
          background-image: url("./images/banner@2x.png");
        }
      }

      @media screen and (-webkit-min-device-pixel-ratio: 3) {
        .img {
          background-image: url("./images/banner@3x.png");
        }
      }
    </style>
  </head>
  <body>
    <div class="img"></div>
    <!-- <img class="img" src="./images/banner.png" />
    <script>
      setImg();
      function setImg() {
        let dpr = window.devicePixelRatio;

        const imgs = document.querySelectorAll("img");

        if (dpr >= 3) {
          dpr = 3;
        } else if (dpr >= 2) {
          dpr = 2;
        } else {
          dpr = 1;
        }

        if (dpr === 1) return;

        imgs.forEach((img) => {
          // a -> images/banner
          // b -> png
          const imgArr = img.src.split("/");
          const [a, b] = imgArr[imgArr.length - 1].split(".");
          // images/banner@2x.png
          imgArr[imgArr.length - 1] = a + `@${dpr}x.` + b;
          img.src = imgArr.join("/");
        });
      }
    </script> -->
  </body>
</html>
